<?php

namespace App\Kuafu\Mybank\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class MybankBatchNoRecordModel extends BaseModel
{
    use HasFactory, KfSoftDeletes, KfUid;

    protected $connection = 'mysql';
    protected $table      = "mybank_batch_no_record";

    protected $fillable = [
        'id',
        'billRecordId',
        'type',
        'channelType',
        'tradeType',
        'batchNo',
        'reconDt',
        'mybankOrderNo',
        'outTradeNo',
        'channelTradeNo',
        'outRefundNo',
        'channelRefundNo',
        'tradeAmount',
        'actualAmount',
        'channelFeeAmount',
        'ccy',
        'userId',
        'merchantId',
        'status',
        'remark',
        'createTime',
        'tradeTime',
        'acquireId',
        'flagMark',
        'createdAt',
        'updatedAt',
        'createdByUid',
        'updatedByUid',
        'isDeleted',
    ];
    const DEFAULT_FLAG_MARK = 0;
    const MATCH_FLAG_MARK   = 1;

    const MAPPING_FLAG_MARK = [
        self::DEFAULT_FLAG_MARK => '未匹配',
        self::MATCH_FLAG_MARK   => '已匹配',
    ];

    const DEFAULT_TYPE_MEITUAN = 1;
    const DEFAULT_TYPE_ELE     = 2;
    const DEFAULT_TYPE_CANTEEN = 3;

    const MAPPING_TYPE_TEXT = [
        self::DEFAULT_TYPE_MEITUAN => '美团',
        self::DEFAULT_TYPE_ELE     => '饿了么',
        self::DEFAULT_TYPE_CANTEEN => '堂食',
    ];

    public static function createData($data): bool
    {
        return self::query()->insert($data);
    }


    public static function getCount($flagMark): int
    {
        return self::query()->where('flagMark', $flagMark)->count();
    }
}
